# Maintainer: David Runge <dvzrv@archlinux.org>

_name=JACK-Client
pkgname=python-jack-client
pkgver=0.5.4
pkgrel=3
pkgdesc="JACK Audio Connection Kit (JACK) Client for Python"
arch=(any)
url="https://github.com/spatialaudio/jackclient-python/"
license=(MIT)
depends=(
  jack
  python
  python-cffi
)
makedepends=(
  python-build
  python-installer
  python-setuptools
  python-wheel
)
checkdepends=(
  jack2
  procps-ng
  python-pytest
  util-linux
)
optdepends=('python-numpy: Access input/output buffers as numpy arrays')
source=(https://files.pythonhosted.org/packages/source/${_name::1}/$_name/$_name-$pkgver.tar.gz)
sha512sums=('bc75d1b58a10c855ab26fbb123ed6774f182a06501e6f31efffdd7c82d384761053dddd7af8315969f67421e4ba17bfc0b49f63f0454c8cc18b4b8385b928d26')
b2sums=('3130342714f0634abacc74c9aa4a7edac70087db82439197717c104e3b0cafc00916fc8d425b2b99c98df82d1c7a2c44a4df8021e84a2209301c19f5b1ae9d96')

build() {
  cd $_name-$pkgver
  python -m build --wheel --no-isolation
}

check() {
  local _site_packages=$(python -c "import site; print(site.getsitepackages()[0])")

  cd $_name-$pkgver
  # install to temporary location
  python -m installer --destdir=test_dir dist/*.whl
  export PYTHONPATH="test_dir/$_site_packages:$PYTHONPATH"
  # start dummy jack server
  jackd -d dummy &
  pytest -vv
  kill -9 $(pgrep jackd)
}

package() {
  cd $_name-$pkgver
  python -m installer --destdir="$pkgdir" dist/*.whl
  install -vDm 644 LICENSE -t "$pkgdir/usr/share/licenses/$pkgname/"
  install -vDm 644 {CONTRIBUTING,NEWS,README}.rst -t "$pkgdir/usr/share/doc/$pkgname/"
  install -vDm 755 examples/*.py -t "$pkgdir/usr/share/doc/$pkgname/examples/"
}
